package logic

import (
	"context"
	"projectes/models/mysql"

	"projectes/projectrpc/internal/svc"
	"projectes/projectrpc/projectrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type SortListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSortListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SortListLogic {
	return &SortListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SortListLogic) SortList(in *projectrpc.SortListRequest) (*projectrpc.SortListResponse, error) {
	// todo: add your logic here and delete this line

	var Sort []mysql.Sort
	mysql.DB.Debug().Model(Sort).Find(&Sort)

	var sliceStruct []*projectrpc.ListStruct

	for _, Sorts := range Sort {
		list := &projectrpc.ListStruct{
			Sort:        Sorts.Sort,
			ProductCode: Sorts.ProductCode,
			ProductName: Sorts.ProductName,
			Number:      int64(Sorts.Number),
			Price:       float32(Sorts.Price),
			Cost:        int64(Sorts.Cost),
			Img:         Sorts.Img,
			UserId:      int64(Sorts.UserId),
		}
		sliceStruct = append(sliceStruct, list)
	}

	return &projectrpc.SortListResponse{Listt: sliceStruct}, nil
}
